package com.javafactroy.kunlong;

import model.base.com.javafactroy.kunlong.ReturnPageInfo;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import com.github.jsonzou.jmockdata.JMockData;
import java.util.List;
import com.javafactroy.kunlong.data.entity.EmployeeApiEntity;
import com.javafactroy.kunlong.data.service.EmployeeService;
import com.javafactroy.kunlong.web.EmployeeWeb;

import utils.com.javafactroy.kunlong.common.CommonUtils;
import com.github.jsonzou.jmockdata.JMockData;
import com.github.jsonzou.jmockdata.MockConfig;

import org.junit.jupiter.api.*;

/**
*  @author raymond.lei@163.com
*  @date   2024-04-07 21:27:00

*/

@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)
@Slf4j
@SpringBootTest(classes = {WebDbAgent.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class EmployeeTestWeb {

   // Logger log = (Logger) LoggerFactory.getILoggerFactory().getLogger("ROOT");
   @Autowired
   EmployeeWeb web;

   String pkeyField = "id";
   String pkeyProp = "id";

   public EmployeeApiEntity mock() {
        MockConfig mockConfig = new MockConfig()
                .doubleRange(1e-9d, 1111222221119999.99999d)
                .floatRange(1e-8f, 111111122221119999.99999f)
                .decimalScale(52).excludes(pkeyProp, "orderBys")
                .subConfig("status").intRange(0, 9).globalConfig();
        EmployeeApiEntity entity = JMockData.mock(EmployeeApiEntity.class, mockConfig);
        log.info("mock entity = {}", CommonUtils.toJSONString(entity));
        return entity;
    }


    @BeforeEach
    void setUp() {
        log.info("setUp{}", "...");
    }

    @AfterEach
    void tearDown() {
        log.info("tearDown{}", "...");
    }

    @Test
    public void test001_query() {

        EmployeeApiEntity  param = new EmployeeApiEntity() ;
        // param.like("mobileNo", "186");
        // param.notBetween("id", "1");
        // param.eq("opBy",-1);
        ReturnPageInfo<EmployeeApiEntity> pageInfo = web.query(param);

        log.info("query pageInfo = {}", CommonUtils.toJSONString(pageInfo));

    }

    @Test
    public void test002_selectByPkey() {
        EmployeeApiEntity list = web.selectByPkey(1l);
        //log.info("list={}", list);

    }

    @Test
    public void test003_save() {

        EmployeeApiEntity entity = mock();
        //service.save(entity.setShopName("122").setContact("ddl"));

        web.save(entity);
        log.info("save entity = {}", entity);

    }
}
